<!--
 * @Descripttion: 
 * @version: 1.0.0
 * @Author: zhangti
 * @Date: 2020-07-24 17:56:40
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-05-09 15:20:46
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Cesium 相控雷达</title>
  <script src="Cesium/Cesium.js"></script>
  <link href="Cesium/Widgets/widgets.css" rel="stylesheet" />
  <script src="plugin/CesiumGeometry.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    html,
    body,
    #d3map {
      width: 100%;
      height: 100%;
      overflow: hidden;
    }

    #btn {
      position: absolute;
      top: 50px;
      left: 50px;
    }
  </style>
</head>

<body>
  <div id="d3map"></div>
  <div id="btn">
    <button onclick="remove()">删除</button>
  </div>
  <script>
    // init viewer
    let viewer = new Cesium.Viewer('d3map', {
      imageryProvider: new Cesium.UrlTemplateImageryProvider({
        url: 'https://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}'
      }),
    })

    // create radar
    let r = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(90), Cesium.Math.toRadians(0), Cesium.Math.toRadians(0))
    let l = Cesium.Cartesian3.fromDegrees(117.224, 31.819, 128)
    let sensorEntity = viewer.entities.add({
      position: l,
      orientation: Cesium.Transforms.headingPitchRollQuaternion(l, r),
      rectangularSensor: new Cesium.RectangularSensorGraphics({
        radius: 100000,
        xHalfAngle: Cesium.Math.toRadians(45),
        yHalfAngle: Cesium.Math.toRadians(45),
        material: new Cesium.Color(1.0, 0.0, 1.0, 0.4),
        lineColor: new Cesium.Color(1.0, 0.0, 1.0, 1.0),
        showScanPlane: true,
        scanPlaneColor: new Cesium.Color(1.0, 0.0, 1.0, 1.0),
        scanPlaneMode: 'vertical',
        scanPlaneRate: 3,
        showThroughEllipsoid: !1,
      }),
    })
    viewer.flyTo(sensorEntity)
    const remove = () => viewer.entities.remove(sensorEntity)
  </script>
</body>

</html>